<template>
	<view class="detail-son">
		<u-sticky>
			<view class="detail-top" v-if="data[0]">
				{{year}}年{{mm}}月   {{title}}
			</view>
		</u-sticky>
		<view v-if="number">
			<view class="detail-list flex" v-for="(item,i) in data" :key="i">
				<view class="left">
					<view class="title">
						{{item.title}}
					</view>
					<view class="time">
						{{item.date}}
					</view>
				</view>
				<view class="right">
					+{{item.integral}}
				</view>
			</view>
		</view>
		<view v-else>
			<view class="detail-list flex" v-for="(item,i) in data" :key="i">
				<view class="left">
					<view class="title">
						{{item.title}}
					</view>
					<view class="time">
						{{item.rewardTime}}
					</view>
				</view>
				<view class="right">
					{{title=='打赏收入'? '+':"-"}}{{item.rewardQuantity}}
				</view>
			</view>
		</view>
		
		<uniBall></uniBall>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: uni.getStorageSync("Pduser"),
				month:"",
				number:"",
				data:[],
				mm:"",
				title:"",
				year:""
			}
		},
		onLoad(opt) {
			this.year = opt.month.substring(0,4)
			console.log(this.year)
			this.month = opt.month
			this.mm = opt.month.substring(5,opt.month.length)
			this.title = opt.title
			if(opt.number){
				this.number = opt.number
				this.getDetails()
			}else{
				this.getDetails2()
			}
		},
		methods: {
			getDetails() {
				this.$myRequest
					.get("/mob/iteration/selectIntegralByMonth", {
						userId: this.userInfo.id,
						month: this.month,
						number:this.number
					}).then(res => {
						console.log(res)
						this.data = res.recordList;
					})
			},
			getDetails2() {
				this.$myRequest
					.get("/mob/iteration/selectIntegralByYear", {
						userId: this.userInfo.id,
						year: this.year,
					}).then(res => {
						/* 后端接口返回未排序，前端旋转 */
						res.RewardExpenditureRecords.reverse()
						res.RewardIncomeRecords.reverse()
						if (this.title == "打赏收入") {
							this.data = res.RewardIncomeRecords.filter(val=>val.rewardTime.includes(this.year))
						}else{
							this.data = res.RewardExpenditureRecords.filter(val=>val.rewardTime.includes(this.year))
						}
			
					})
			},
		}
	}
</script>

<style lang="less" scoped>
	page{
		background-color: #fff;
	}
	.detail-top{
		padding: 29rpx 0;
		margin-bottom: 10rpx;
		text-align: center;
		background: #FFFFFF;
		box-shadow: 0rpx 1rpx 6rpx 1rpx rgba(0,0,0,0.08);
		font-size: 30rpx;
		font-weight: 500;
		color: #64B6A8;
	}
	
	.detail-list{
		padding: 30rpx 0;
		margin: 0 37rpx 0 50rpx;
		border-bottom: 1rpx solid #D6D6D6;
		align-items: center;
		justify-content: space-between;
		
		.left{
			font-size: 28rpx;
			color: #333333;
			.title{
				margin-bottom: 10rpx;
			}
			.time{
				font-size: 26rpx;
				color: #A3AAB0;
			}
		}
		
	}
	
	
</style>
